package com.itheima.mapper;

import com.itheima.pojo.*;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface TeacherMapper {

    List<CourseContent> selectDiscuss(String name, Integer gender, LocalDateTime begin, LocalDateTime end);

    List<TeacherCourse> selectCourse(String name);

    @Insert("insert into tb_course (teacher_id,name, context, create_time, update_time, classify_id) " +
            "values (#{teacherId},#{name},#{context},#{creatTime},#{updateTime},#{classifyId});")
    @Options(keyProperty = "id", useGeneratedKeys = true)
    void insertCourse(Course course);

    @Select("select * from tb_course where name = #{name};")
    Course selectCourseByName(String name);

    @Insert("insert into tb_classify (id,name, create_time, update_time, course_id) " +
            "values (#{id},#{name},#{createTime},#{updateTime},#{courseId});")
    void insertClassify(Classify classify);//插入课程分类

    @Select("select * from tb_classify where name = #{name}")
    Classify selectClassifyByName(String name);

    @Delete("delete from tb_classify where id = #{classifyId};")
    void deleteCourses(Integer classifyId);

    @Delete("delete from tb_course where classify_id = #{classifyId};")
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    void deleteCourseByClassifyId(Integer classifyId);

    void updateCourse(Course course);

    @Select("select * from tb_teacher where id = #{id};")
    Teacher getTeacherById(Integer id);


    void updateTeacher(Teacher teacher);
}
